package com.umeox.watch.moto.chat.adapter

import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import androidx.viewpager.widget.ViewPager
import java.util.ArrayList

/**
 * Created by Rambo 2021/9/6
 * Describe:
 */
class ChatMoreAdapter(private val viewContainer: ArrayList<View>) : PagerAdapter() {


    override fun getCount(): Int {
        return viewContainer.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view === `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        if (viewContainer[position].parent != null) {
            (viewContainer[position].parent as ViewPager).removeView(viewContainer[position])
        }
        container.addView(viewContainer[position], 0)
        return viewContainer[position]
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        container.removeView(viewContainer[position])
    }
}